package com.edoomath.api.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.edoomath.entity.usercourse.UserCourse;
import com.edoomath.entity.usercourse.UserCourseAttribute;
import com.edoomath.entity.usercourse.UserCourseItem;
import com.edoomath.entity.usercourse.UserCourseStat;
import com.edoomath.entity.usercourse.UserCourseTask;

/**
 * 
 * @author mohanlan
 *
 */
@Dao(value = "hibernate")
public interface UserCourseDao {
	
	/**
	 * 
	 * @param unionid
	 * @return
	 */
	@Query("FROM UserCourse WHERE unionid = :unionid AND disabled = false")
	public List<UserCourse> listUserCourse(@Variable("unionid") String unionid);
	
	/**
	 * 
	 * @param unionid
	 * @param courseId
	 * @return
	 */
	@Query("FROM UserCourse WHERE unionid = :unionid AND course.id = :courseId AND disabled = false")
    public UserCourse loadUserCourse(@Variable("unionid") String unionid, @Variable("courseId") Long courseId);
	
	/**
	 * 
	 * @param userCourse
	 * @return
	 */
	@Query("FROM UserCourseStat WHERE userCourse = :userCourse")
    public UserCourseStat loadUserCourseStat(@Variable("userCourse") UserCourse userCourse);
	
	/**
	 * 
	 * @param unionid
	 * @return
	 */
	@Query("FROM UserCourseStat WHERE unionid = :unionid")
	public List<UserCourseStat> listUserCourseStat(@Variable("unionid") String unionid);
	
	/**
	 * 
	 * @param userCourse
	 * @return
	 */
	@Query("FROM UserCourseItem WHERE disabled = false AND userCourse = :userCourse")
	public List<UserCourseItem> listUserCourseItem(@Variable("userCourse") UserCourse userCourse);
	
	/**
	 * 
	 * @param userCourses
	 * @return
	 */
	@Query("FROM UserCourseAttribute WHERE userCourse in (:userCourses) AND disabled = false")
    public List<UserCourseAttribute> listAttrs(@Variable("userCourses") List<UserCourse> userCourses);
	
	/**
	 * 
	 * @param userCourse
	 * @return
	 */
	@Query("FROM UserCourseAttribute WHERE userCourse = :userCourse AND disabled = false")
    public List<UserCourseAttribute> listAttrs(@Variable("userCourse") UserCourse userCourse);
	
	/**
	 * 
	 * @param userCourse
	 * @return
	 */
	@Query("FROM UserCourseTask WHERE userCourse = :userCourse AND disabled = false")
	public List<UserCourseTask> listUserCourseTasks(@Variable("userCourse") UserCourse userCourse);
	
}
